<form action="cmsWebFile/doUpload?callbackType=closeCurrent&navTabId=cmsWebFile/list" method="post" autocomplete="off" enctype="multipart/form-data" class="pageForm required-validate" onsubmit="return iframeCallback(this, dialogAjaxDone)">
    <input type="hidden" name="_csrf" value="<@tools.csrfToken admin=true/>"/>
    <div class="pageFormContent" layoutH>
        <dl class="nowrap">
            <dt><@t.page 'file'/>:</dt>
            <dd>
                <input type="hidden" name="path" value="${path!}"/>
                <input type="file" name="files" class="required" size="30" multiple="multiple"/>
                <label class="unzip hide"><input type="checkbox" name="unzip" class="form-check-input"><@t.page 'button.decompress'/></label>
                <label class="overwrite hide"><input type="checkbox" name="overwrite" class="form-check-input" checked="checked"><@t.page 'upload.overwrite'/></label>
                <span class="info warning hide">
                    <@t.message "verify.custom.fileType"/>
                    <a href="sysConfigData/edit.html?code=safe" target="navTab" rel="sysConfigData/edit"><i class="icon-edit"></i><@t.page 'config_data.edit'/></a>
                </span>
            </dd>
            <dl class="nowrap zip hide">
                <dt><@t.page 'decompress.position'/>:</dt>
                <dd>
                    <label><input type="radio" name="here" value="false" checked="checked"/><@t.page 'decompress.position.new'/></label>
                    <label><input type="radio" name="here" value="true"/><@t.page 'decompress.position.here'/></label>
                    <label><input type="checkbox" name="zipOverwrite" class="form-check-input" checked="checked"><@t.page 'upload.overwrite'/></label>
                </dd>
            </dl>
            <dl class="nowrap zip hide">
                <dt><@t.page 'file.encoding'/>:</dt>
                <dd>
                    <label><input type="radio" name="encoding" value="utf-8" checked="checked"/><@t.page 'file.encoding.utf8'/></label>
                    <label><input type="radio" name="encoding" value="gbk"/><@t.page 'file.encoding.gbk'/></label>
                </dd>
            </dl>
        </dl>
    </div>
    <div class="formBar">
        <ul>
            <li><button type="submit" class="buttonActive" title="ctrl+s"><@t.page 'upload'/></button></li>
            <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
        </ul>
    </div>
</form>
<script>
<#assign safeFileTypes=[]/>
<@sys.configData code="safe"><#assign safeFileTypes=(object.allow_files?split(','))![]/></@sys.configData>
$(".pageFormContent",$.pdialog.getCurrent()).on("change","input[type=file]",function(){
    if($(this).length && $(this)[0].files){
        var fileNames = [];
        $('.warning',$.pdialog.getCurrent()).hide();
        $('.zip',$.pdialog.getCurrent()).hide();
        $('.unzip',$.pdialog.getCurrent()).hide();
        $.each($(this)[0].files, function(i, file) {
            fileNames.push(file.name);
            if(-1 == $.inArray(file.name.toLowerCase().substring(file.name.lastIndexOf(".")) , [<#list safeFileTypes as type>"${type}"<#sep>,</#list>])){
                $('.warning',$.pdialog.getCurrent()).show();
            }
            if(file.name.substring(file.name.toLowerCase().lastIndexOf(".")) == ".zip"){
                $('.unzip',$.pdialog.getCurrent()).show();
            }
        });
       
        $.ajax({
            url:'cmsWebFile/check',
            type: 'POST',
            dataType: "json",
            async: false,
            data: {
                fileNames : fileNames,
                path : $("input[name=path]",$.pdialog.getCurrent()).val(),
                _csrf : $("input[name=_csrf]",$.pdialog.getCurrent()).val()
            },
            success: function (result) {
                if(result){
                    $('.overwrite',$.pdialog.getCurrent()).show();
                } else {
                    $('.overwrite',$.pdialog.getCurrent()).hide();
                }
            }
        });
    }
});
$("input[name=unzip]",$.pdialog.getCurrent()).on("click", function(){
    if($(this).is(':checked')) {
        $('.zip',$.pdialog.getCurrent()).show();
        $('.overwrite',$.pdialog.getCurrent()).hide();
    } else {
        $('.zip',$.pdialog.getCurrent()).hide();
        $('.overwrite',$.pdialog.getCurrent()).show();
    }
});
</script>